<?php
class GeryTemplateContext extends GeryProxyContext {
	
	private $templateName;
	
	public function __construct(IGeryContext $context, $templateName) {
		parent::__construct($context);
		
		$this->templateName = $templateName;
	}
	
	function getTemplateName() {
		return $this->templateName;
	}
	
	function registerMacro($templateClass, $macroName) {
		$this->getInternalHouseKeepingContext()->registerMacro($templateClass, $macroName);
	}
	
	public function isMacroRegistered($macroName) {
		return $this->getInternalHouseKeepingContext()->isMacroRegistered($macroName);
	}
	
	function callMacro($macroName, $parameters) {
		return $this->getInternalHouseKeepingContext()->callMacro($macroName, $this, $parameters);	
	}
	
	public function getTemplate($resourceName) {
		return $this->getInternalHouseKeepingContext()->getTemplate($resourceName);
	}
	
	public function getResource($resourceName) {
		return $this->getInternalHouseKeepingContext()->getResource($resourceName);
	}
	
	public function log($message, $lineNumber, $level = LOG_LEVEL_INFO) {
		
		$location = new TemplateLocation($lineNumber, $this->templateName);
		
		$this->getLogger()->log($message . ' in ' . $location->__toString(), $level);	

		if ($level == LOG_LEVEL_FATAL) {
			throw new GeryRuntimeException($message, $location);
		}
	}
	
	/**
	 * Get the engine logger
	 *
	 * @return Logger
	 */
	function getLogger() {
		return $this->getInternalHouseKeepingContext()->getLogger();
	}
}
?>